Converting and Matching Colors
Although conversion among color spaces happens automatically whenever necessary during the drawing process, you can also explicitly convert colors if you need to. The following code fragment usesGXConvertColor
to modify the hue of a shape, preserving its luminance and saturation. Such a technique is one way to perform color animation. The code gets the color of shapetheShape
, converts it to HSV space, increases the hue value just enough to make a perceptible difference, reassigns the color to the shape, and draws the shape:
gxColor oldColor; GXGetShapeColor(theShape, &oldColor); GXConvertColor(&oldColor, hsvSpace, nil, nil); oldColor.element.hsv.hue += 0x300; GXSetShapeColor(theShape, &oldColor); GXDrawShape(theShape);(Note that the finalnil
parameter in the call to GXConvertColor means that the converted color reassigned to the shape uses the default color profile, whether or not the original one did.)Color matching happens automatically whenever you draw a shape or convert colors. If the profile reference in a color is
nil
, color correction still occurs when needed, as when converting from RGB to CMYK color space. In those cases, the default profile is used.In some cases, you may want to prevent color matching from occurring for an individual color, such as when comparing or calibrating different devices. If you attach a zero-length profile to a color, QuickDraw GX performs no matching when that color is drawn or converted to another color space.
To prevent color matching from occurring during all drawing to a given view port, clear the
gxEnableMatchPort
attribute of that view port. Note that, because color matching can slow down the drawing process, this attribute is cleared by default on all view ports. Therefore, if you want color matching to occur when drawing to the screen, you must explicitly setgxEnableMatchPort
. Even if you do want matching to occur, you might still cleargxEnableMatchPort
temporarily during scrolling or other repetitive drawing processes. (For printing, QuickDraw GX automatically takes care of making sure that color matching occurs when it is needed.)If you want to specify a particular kind of color-matching method other than the one specified in the profile attached to the color you are matching, your application can either modify the information in the color profile object using QuickDraw GX calls, or make calls to the ColorSync Utilities to specify the one you want.
To allow the user to preview on the screen what printing would look like, you can mimic on the monitor the profile characteristics of the printer. You need to convert the color you are drawing to the color space of the printer--applying the printer's color profile--and then convert that color back to the monitor's color space--applying the monitor's color profile--and then draw. One way to do that is to create an offscreen view group with the printer's color space and color profile, and draw into a view port in that view group. Then, draw from the bitmap of the offscreen view port into the view port of the monitor.
Color matching is discussed in the section "Color Conversion and Color Matching" beginning on page 4-26. Color profiles, the default profile, and zero-length profiles are discussed in the section "About Color Profile Objects" beginning on page 4-35. The
gxEnableMatchPort
view port attribute is described in the chapter "View-Related Devices" in this book.